
<template>
    <div class="contract-list-page change-repayment-date-list">
        <Card>
            <ChangeForm
                :isSP="isSP"
                :formValidate="formValidate"
                :formValidateRule="formValidateRule"
                :dataDict="dataDict"
                :businessSource="businessSource"
                :loading="loading"
                @showModal="showModal"
                @getList="getList"
            />
            <ChangeTable
                :isSP="isSP"
                :formValidate="formValidate"
                :dataDict="dataDict"
                :contractTable="contractTable"
                :businessSource="businessSource"
                :loading="loading"
                @getList="getList"
                @showContractDetial="showContractDetial"
            />
        </Card>
        <ActivatedCase
            :isSP="isSP"
            :dataDict="dataDict"
            :modal="modal"
            :handleBusiness="'repaymentDateChange'"
            :contractBusiness="contractBusiness"
            modalTitle="已激活案件列表"
            @showContractDetial="showContractDetial"
            @closeModal="closeModal"
        />
    </div>
</template>
<script>
// api
import { mapGetters } from "vuex";
import {
    getRepaymentChangeList,
} from "_p/basic/api/contract/post-loan-info-change/change-repayment";
import { getDictDataList } from "_p/basic/assets/contract/js/utils";

import { channelType, businessSource } from "_p/basic/api/contract/channel-type/channel-type";

import { isPhoneValiate } from "_p/basic/assets/contract/js/utils";

import ChangeForm from "./ChangeForm";
import ChangeTable from "./ChangeTable";
import ActivatedCase from "_p/basic/pages/contract/common/activated-case/index";

export default {
    // 还款日变更
    name: "ChangeRepaymentDateList",
    components: {
        ChangeForm,
        ChangeTable,
        ActivatedCase
    },
    props: {},
    data() {
        return {
            businessSource:"",
            //校验提前结清，展期，未闭环的还款日变更申请，合同关闭，撤销收款
            contractBusiness:["advanceSettle","extension","repaymentDateChange","closeContract","collectionRevoke"],
            pageNo: 1,
            // 是否是合作商
            isSP: false,
            loading: false,
            // 日期区间
            isDateErr: false,
            formValidate: {
                applyNo: "", // 申请编号
                contractNo: "", // 合同号
                custName: "", // 客户名称
                dataSource: null, //来源
                processStatus: null, //处理状态
                pageNumber: 1, // integer($int32) // 当前页
                pageSize: 10 //integer($int32) // 多少条
            },
            formValidateRule: {
                phone: [
                    {
                        validator: (rule, value, callback) => {
                            isPhoneValiate(rule, value, callback);
                        },
                        trigger: "blur"
                    }
                ]
            },

            contractTable: {
                current: 1, // 表格当前页
                pages: 0,
                searchCount: false,
                size:10,
                total: 0,
                orders: [],
                records: []
            },
            //  处理状态(processStatus)   来源(dataSource)  变更主体(PersonRoleType)  案件类型
            // 已激活案件列表: contractStatus 合同状态 channelType 渠道类型
            dicttArr: ["contractStatus", "channelType", "processStatus", "dataSource", "PersonRoleType"],
            dataDict: {}, // 数据字典
            modal: false
        };
    },
    computed: {
        ...mapGetters({ userInfo: "userInfo", roleType: "roles" }),
    },
    created() {
        this.isSP = channelType(this.$route.meta.params);
        // businessSource 通过 roleType 获取 值: BUSINESS_PEOPLE / SP
        this.businessSource = businessSource(this.roleType);
    },
    mounted() {
    },
    activated() {
        this.init();
    },
    methods: {
        init() {
           this.isSP = channelType(this.$route.meta.params);
            // businessSource 通过 roleType 获取 值: BUSINESS_PEOPLE / SP
            this.businessSource = businessSource(this.roleType);
            this.getList(this.formValidate);
            this.getDictDataList();
        },
        getDictDataList() {
            getDictDataList(this.dicttArr).then(res => {
                this.dataDict = res;
            });
        },
        getList(data) {
            this.loading = true;
            getRepaymentChangeList(data).then(res => {
                this.loading = false;
                if (res.code === "0000") {
                    this.contractTable = res.data;
                } else {
                    this.$Message.error("Fail!");
                }
            });
        },

        // 弹窗
        showModal() {
            this.modal = true;
        },
        closeModal() {
            this.modal = false;
        },
        showContractDetial(params, type) {
            if (!params && !params.contractNo) return;
            if (type) params.readOnly = true;
            this.modal = false;
            this.afs.newTab(
                this,
                "projects/basic/pages/contract/post-loan-info-change/change-repayment-date-detial/index",
                "还款日变更详情",
                "ios-add",
                params,
                "change-repayment-date-detail-" + this.pageNo,
                [],
                true
            );
            this.pageNo += 1;
        }
    }
};
</script>
<style lang="less" >
@import "../../../../styles/common/form.less";
</style>
